package com.wty.learnsping.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class RequestController {

    @RequestMapping("/test1")
    public String test1(){
        System.out.println("调用/test1");
        return "return test1";
    }

    @RequestMapping("/test2")
    public String test2(){
        System.out.println("调用/test2");
        return "return test2";
    }


    @RequestMapping("/test3")
    public void test3(){
        System.out.println("调用/test3");
        throw new RuntimeException("我手动抛出的异常");
    }


    @RequestMapping("/datetest")
    public void datetest(Date date){
        System.out.println(date);
    }

    /**
     * consumes指定的是Http请求的Content-Type，浏览器的该值一般为null
     * 一般用于限定ajax请求时限定
     * @return
     */
    @RequestMapping(value = "/testconsumes",consumes = "application/json")
    public String testConsumes(){
        return "return consumes";
    }


    /**
     * produces对应的浏览器的Accept字段，浏览器的Accept通常设置为*.*,匹配所有
     * @return
     */
    @RequestMapping(value = "testproduces",produces = MediaType.APPLICATION_ATOM_XML_VALUE)
    public String testProduces(){
        return "return produces";
    }


    /**
     * 存在参数 通过
     * 不存在参数 通过
     * 参数等于某一个值 通过
     * headers同理 取的是http请求头中的header
     * @return
     */
    @RequestMapping(value = "testparams",params = "action=1")
    public String testParams(){
        return "return params";
    }







}
